﻿using AutoMapper;
using B.S.Material.Domain.BOM;
using B.S.Material.Domain.Production_rejection;
using B.S.Material.ErrorCode;
using B.S.Material.Wirth.Api.Applications.Command.StrippingDetailsCommand;
using MediatR;
using SqlSugar;

namespace B.S.Material.Wirth.Api.Applications.Handler.StrippingDetailsHandler
{
    public class DelStrippingDetailsHandelr : IRequestHandler<DelStrippingDetailsCommand, ApiResult<int>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public DelStrippingDetailsHandelr(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(DelStrippingDetailsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var list = await db.Queryable<StrippingDetails>().FirstAsync(x => x.StrippingDetailsId == request.StrippingDetailsId);
            list.IsDel = true;
            result.data = await db.Updateable(list).ExecuteCommandAsync();
            if (result.data > 0)
            {
                result.Code = ApiEnum.删除成功;
                result.MAG = ApiEnum.删除成功.ToString();
            }
            else
            {
                result.Code = ApiEnum.删除失败;
                result.MAG = ApiEnum.删除失败.ToString();
            }
            return result;
        }
    }
}
